// 修改资料
<template>
  <el-dialog title="修改资料" :visible.sync="modifyingData" width="30%" center :show-close="false">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
      size="mini"
    >
      <el-form-item label="用户账号" prop="user">
        <el-input v-model="ruleForm.user" disabled></el-input>
      </el-form-item>
      <el-form-item label="联系手机" prop="tel">
        <el-input v-model="ruleForm.tel" ></el-input>
      </el-form-item>
      <el-form-item label="联系邮箱" prop="mailbox">
        <el-input v-model="ruleForm.mailbox"></el-input>
      </el-form-item>
      <el-form-item label="用户描述" prop="desc">
        <el-input type="textarea" v-model="ruleForm.desc"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')" size="mini">保存数据</el-button>
        <el-button @click="cancel" size="mini">取消编辑</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      ruleForm: {
        user: 'admin',
        tel: '',
        mailbox: '',
        desc: ''
      },
      rules: {
        user: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        tel:
          [
            { required: true, message: '电话不能为空', trigger: 'blur'},
            { min: 11, max: 11, message: '请输入正确的手机号码...', trigger: 'blur' }
          ],
        mailbox: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ],
        desc: [
          { required: true, message: '请填写描述', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$store.commit('myCommon/modifyingData', false)
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false;
        }
      })
    },

    // 取消编辑
    cancel() {
      this.$store.commit('myCommon/modifyingData', false)
    }
  },
  computed: {
    ...mapState('myCommon', ['modifyingData'])
  }
}
</script>

<style lang='scss' scoped>
div {
  .el-row {
    /deep/ .el-dialog__wrapper {
      .el-dialog {
        .el-dialog__header {
          .el-dialog__title {
            color: aqua !important;
          }
        }
      }
    }
  }
}
</style>